export const getIpName = () => {
	if(uni.getStorageSync('newprovince')){
		return new Promise((resolve,reject) => {
			
			if((Date.now() - uni.getStorageSync('newprovince').time) > 1000 * 60 * 60){
				province().then(res => {
					resolve(res)
				})
			}else{
				resolve(uni.getStorageSync('newprovince').province)
			}
		})
	}else {
		return new Promise((resolve,reject) => {
			province().then(res => {
				resolve(res)
			})
		})
	}
	
}

function province(){
	return new Promise((resolve,reject) => {
		uni.request({
			url:'https://restapi.amap.com/v3/ip?key=5997394bcf208ffd9ecc45fb553be719',
			success(res) {
				let str = ''
				
				if(typeof(res.data.province) == 'string'){
					str = res.data.province
					
				}else{
					str = '火星'
				}
				
				let obj = {
					province:str,
					time:Date.now()
				}
				resolve(str)
				uni.setStorageSync('newprovince',obj );
			}
		})
	})
}